// Generic 泛型
function join_generic<T, P>(first: T, second: P) {
  return `${first}${second}`
}

join_generic<string, number>('12', 123);

// 泛型中数组的使用
function myFun_generic<T>(params: T[] | Array<T>) {
  return params
}

myFun_generic<string>(['1,2,3', '1,2,3'])

// 类中使用泛型
// 泛型中的继承

interface Girl_selectXjj {
  name: string
}

class SelectXjj<T extends Girl_selectXjj>{
  constructor(private girls: T[]) { }
  getGirl(index: number): string {
    return this.girls[index].name
  }
}



const selectXjj = new SelectXjj([{ name: 'jx' }, { name: 'pp' }, { name: 'ht' }])
console.log(selectXjj.getGirl(0))

// 泛型中的约束 

class SelectXjj1<T extends number | string>{
  constructor(private girls: T[]) { }
  getGirl(index: number): T {
    return this.girls[index]
  }
}



const selectXjj1 = new SelectXjj1<string>(['jx', 'pp', 'ht'])
console.log(selectXjj1.getGirl(0))